'''
Desc: 实现太阳类
Author: 陈爱国
Date: 2024-08-24 09:00:30
'''
import pygame
import random

class Sun(pygame.sprite.Sprite):
    def __init__(self, rect):
        # 调用父类构造方法
        super(Sun, self).__init__()
        # 定义对象图片
        self.image = pygame.image.load('material/images/Sun_1.png').convert_alpha()
        # 图片序列，用于产生动画
        self.images = [pygame.image.load('material/images/Sun_{}.png'.format(i)).convert_alpha() for i in range(1, 18)]
        # 图片的矩形区域
        self.rect = self.images[0].get_rect()

        # 产生的太阳在rect的周围
        offset_top = random.randint(-50, 50)
        offset_left = random.randint(-50, 50)

        # 图片top
        self.rect.top = rect.top + offset_top
        # 图片left
        self.rect.left = rect.left + offset_left

    def update(self, *args):
        self.image = self.images[args[0] % len(self.images)]